import 'dart:core';
import 'dart:ui';

import 'package:dk_flutter_base/dk_ui.dart';

///TabBar + TabBarView
///相当于 Android 原生TabLayout + ViewPage
///有自带 Material Design 动画
///代码实现简单
///支持左右滑动
class DkBottomAppBar extends BottomAppBar {
  DkBottomAppBar.createByParam(BottomAppBarParam param)
      : super(
          key: param?.key,
          color: param?.color,
          elevation: param?.elevation,
          shape: param?.shape,
          clipBehavior: param?.clipBehavior,
          notchMargin: param?.notchMargin,
          child: getChild(param),
        );

  static Widget getChild(BottomAppBarParam param) {
    switch (param?.bottomBarType) {
      case BottomBarType.tab:
        return DkTabBar(param?.tabBarOption);
        break;
      case BottomBarType.navigation:
        return DkBottomNavigationBar(param?.bottomNavigationBarOption);
      case BottomBarType.page:
      case BottomBarType.normal:
      default:
        return null;
    }
  }
}

enum BottomBarType { tab, page, normal, navigation }

class BottomAppBarParam {
  Key key;
  Color color;
  double elevation;
  NotchedShape shape;
  Clip clipBehavior;
  double notchMargin;
  TabBarOption tabBarOption;
  BottomNavigationBarOption bottomNavigationBarOption;
  BottomBarType bottomBarType;

  BottomAppBarParam.withTab(
    this.tabBarOption, {
    this.key,
    this.color,
    this.elevation,
    this.shape,
    this.clipBehavior,
    this.notchMargin,
  }) {
    bottomBarType = BottomBarType.tab;
    initParam();
  }

  BottomAppBarParam.withNavigation(
    this.bottomNavigationBarOption, {
    this.key,
    this.color,
    this.elevation,
    this.shape,
    this.clipBehavior,
    this.notchMargin,
  }) {
    bottomBarType = BottomBarType.navigation;
    initParam();
  }

  void initParam() {
    if (null != elevation && elevation < 0.0) {
      elevation = 0;
    }
    clipBehavior ??= Clip.none;
    notchMargin ??= 4.0;
  }
}
